package de.ryancarmon.validator.exc;

import de.ryancarmon.validator.ValidatorParam;

public class ValidationException extends RuntimeException {
	private static final long serialVersionUID = 1L;

	private ValidatorParam param;
	private Object value;
	private Object paramValue;
	private boolean hasParamValue;

	public ValidationException(ValidatorParam param, Object value) {
		if (param == null)
			throw new IllegalArgumentException("'param' may not be null");

		this.param = param;
		this.value = value;
		this.hasParamValue = false;
	}

	public ValidationException(ValidatorParam param, Object paramValue,
			Object value) {
		if (param == null)
			throw new IllegalArgumentException("'param' may not be null");

		this.param = param;
		this.value = value;
		this.hasParamValue = true;
		this.paramValue = paramValue;
	}

	@Override
	public String getMessage() {
		if (hasParamValue)
			return String.format("Failed validating %1$s(%2$s) for %3$s.",
					param, paramValue, value);

		return String.format("Failed validating %1$s for %2$s",
				param, value);
	}
}
